package exercise;//package exercise;

/*
基础题
1.定义一个Employee类（员工类）
 属性:姓名  年龄 性别 工资
方法:print() 打印员工基本信息
addSal() 给员工加薪1000元 并给出提示涨薪多少元 20000封顶
要求对该类进行封装  年龄在1-100之间     性别男或者女    工资1~20000封顶
 */
public class ex1 {
    public static void main(String[] args) {
        Employee1 employee1 = new Employee1("zs", 18, "男", 17500);
        employee1.addSal();
        employee1.addSal();
        employee1.addSal();
        employee1.addSal();
        employee1.addSal();
        employee1.addSal();
        employee1.addSal();

    }
}

class Employee1 {
    private String name;
    private int age;
    private String sex;
    private double salary;

    public Employee1() {
    }

    public Employee1(String name, int age, String sex, double salary) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.salary = salary;
    }

    public void print() {
        System.out.println("姓名:" + name + "年龄:" + age + "性别:" + sex + "工资:" + salary);
    }

    public void addSal() {
        if (salary + 1000 > 20000) {
            System.out.println("涨薪" + (20000 - salary));
            salary = 20000;
        } else {
            salary += 1000;
            System.out.println("涨薪" + 1000);
        }
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        if (age < 1 || age > 100) {
            System.out.println("年龄不合法,设置为默认值18");
            this.age = 18;
            return;
        }
        this.age = age;
    }

    public void setSex(String sex) {
        if (("男".equals(sex) || "女".equals(sex)))
            this.sex = sex;
        else
            System.out.println("阴阳人？");
    }

    public void setSalary(double salary) {
        if (salary < 1 || salary > 20000) {
            System.out.println("工资不合法,设置为默认值10000");
            this.salary = 10000;
            return;
        }
        this.salary = salary;
    }
}

